<template>
  <div class="charts" ref="chartsRef"></div>
</template>

<script lang="ts">
export default {
  name: "BarChart",
};
</script>

<script lang="ts" setup>
import * as echarts from "echarts";
import { ref, watch } from "vue";
const chartsRef = ref();
const props = defineProps<{
  data: number[];
  axis: string[];
}>();
watch(
  () => props.data,
  () => {
    const myEcharts = echarts.init(chartsRef.value);
    const option = {
      xAxis: {
        data: props.axis,
      },
      yAxis: {
        show: false, // 隐藏y轴
      },
      // 定位
      grid: {
        top: 0,
        bottom: 0,
        left: -5,
        right: -5,
      },
      // 提示组件，鼠标移入有数据提示
      tooltip: {
        trigger: "axis", // 放上去有虚线
      },
      series: [
        {
          name: "实时交易量",
          type: "bar",
          data: props.data,
          itemStyle: {
            color: "#3398db",
          },
          barWidth: 10,
        },
      ],
    };
    myEcharts.setOption(option);
  }
);
</script>

<style scoped>
.charts {
  width: 100%;
  height: 100%;
}
</style>
